package com.jboost.hyk.common.entity;


import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.jboost.common.system.base.entity.JBoostEntity;

import java.util.Date;

/**
 * @Description: 机构的知识点记录（订单）
 * @Author: cxn
 * @Date:   2022-10-24
 * @Version: V1.0
 */
@Data
@TableName("hyk_business_knowledge_point")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="hyk_business_knowledge_point对象", description="机构的知识点记录（订单）")
public class BusinessKnowledgePoint extends JBoostEntity{

    /**businessId*/
    @ApiModelProperty(value = "businessId")
    private String businessId;

    /**购买的知识点 id*/
    @ApiModelProperty(value = "购买的知识点 id")
    private String knowledgeId;

    /**knowledgeVersionId*/
    @ApiModelProperty(value = "knowledgeVersionId")
    private String knowledgeVersionId;

    /**知识有效开始时间*/
    @ApiModelProperty(value = "知识有效开始时间")
    private java.util.Date validStartTime;

    /**知识有效结束时间*/
    @ApiModelProperty(value = "知识有效结束时间")
    private java.util.Date validEndTime;

    /**知识点在机构内被使用次数*/
    @ApiModelProperty(value = "知识点在机构内被使用次数")
    private Integer useNum;

    /**状态：valid-正常；soon_expire-即将到期；expired-已过期；*/
    @ApiModelProperty(value = "状态：valid-正常；soon_expire-即将到期；expired-已过期；")
    private String status;


    @ApiModelProperty(value = "name")
    private String name;

    /**category1Id*/
    @ApiModelProperty(value = "category1Id")
    private String category1Id;

    /**category2Id*/
    @ApiModelProperty(value = "category2Id")
    private String category2Id;

    /**category3Id*/
    @ApiModelProperty(value = "category3Id")
    private String category3Id;

    /**teacherId*/
    @ApiModelProperty(value = "teacherId")
    private String teacherId;

    public String generateStatus() {
        if (null == validStartTime){
            this.status = "valid";
            return this.status;
        }
        if (null == validEndTime){
            this.status = "valid";
            return this.status;
        }
        if (new Date().getTime() > this.validEndTime.getTime()){
            this.status = "expired";
        }else if (new Date().getTime()+1000*60*60*24*15 > this.validEndTime.getTime()){
            this.status = "soon_expire";
        }else {
            this.status = "valid";
        }
        return this.status;
    }

}
